var app = new Framework7({
  // App root element
  root: '#app',
  // App Name
  name: 'My App',
  // App id
  id: 'com.myapp.test',
  // Enable swipe panel
  panel: {
    swipe: 'left',
  },
  // Add default routes
  routes: [
    {
      path: '/register/',
      url: 'controll.php?route=register',
    },
  ],
  // ... other parameters
});

var mainView = app.views.create('.view-main');


var swiper = app.swiper.get('.swiper-container');

//swiper.slideNext();


//选择桌号/要求picker  reserve.php reserveGuest.php 
var pickerDescribe = app.picker.create({
  inputEl: '#table',
    rotateEffect: true,
    cols: [
      {
        textAlign: 'left',
        values: ('包房 包间 卡座 大厅').split(' ')
      },
      {
        values: ('2-3人 4-5人 6-7人 8-9人 10-11人 12-13人 14-15人 16人以上').split(' ')
      },
	  {
        values: ('无 靠窗 私密性好 通风好 要沙发 要宝宝椅 准备水果 其他备注').split(' ')
      },
    ]
});

//选择新菜  in freeNewDish.php in reserve.php
var pickerDevice = app.picker.create({
  inputEl: '#dish',
  cols: [
    {
      textAlign: 'center',
      values: ['Q弹肥肠', '雪花牛肉粒', '荷塘月色', '沙姜冰爽猪手', '招牌水晶鸡', '清爽小甜豆', '雪菜烩竹衣', '香葱煎豆腐', '韭菜柴火香干', '野菜花炒鱼扣', '豉香安化砣粉', '酸藕尖炒脆肚']
    }
  ]
});


var user = new Array();
		
$(document).on('click','#take-button', function () {
		user.table = $("#table").val();
		if(user.table == ""){
			alert("请完善下面预定信息后再点击领取按钮");
		}else{
				window.location.href="controll.php?route=freenewdish";
		}
		
		
	});
	
	
	
var reservation = new Array();
var notificationFull = app.notification.create({
  icon: '<i class="icon demo-icon">订</i>',
  title: '预定成功通知',
  titleRightText: '现在',
  subtitle: '恭喜您预定成功',
  text: '桌号会在5分钟内会以短信方式发送到您手机上',
  closeTimeout: 3000,
});
function getCookie(cname)
{
  var name = cname + "=";
  var ca = document.cookie.split(';');
  for(var i=0; i<ca.length; i++) 
  {
    var c = ca[i].trim();
    if (c.indexOf(name)==0) return c.substring(name.length,c.length);
  }
  return "";
}

//预定处理 in reserve.php reserveGuest.php
$(document).on('click','#reservation', function () {
	reservation.phone = $("#phone").val();
	reservation.name = $("#name").val();
	reservation.date = $("#date").val();
	reservation.time = $("#time").val();
	reservation.desk = $("#table").val();
	reservation.dish = $("#dish").val();
	reservation.backup = $("#backup").val();
	console.log(user);
	
		var CR = getCookie("operated")
			console.log(C);
		
		if(reservation.desk == ""){
		
			alert("请选择好桌位/人数等后再点击提交");
			
		}else if(CR == "1"){
			alert("亲！你已经成功了，请不要重复提交哦");
			
		}else {
		
			$.post('api.php?operation=reservation',{phone:reservation.phone,name:reservation.name,date:reservation.date,time:reservation.time,desk:reservation.desk,dish:reservation.dish,backup:reservation.backup}, function(response){
					
					
					if(response == "1"){
						//alert("预定成功，5分钟内会以短信方式发送桌号到您手机上");
						//notificationFull.open();
						document.cookie="operated=1";
						window.location.assign('controll.php?route=reservesuccess');
						
					}else{
						alert("预定失败，请联系13687177529管理员，不好意思啦");
					}
					
				});
				
		
		}
	
});


//注册会员
$(document).on('click','#register', function () {
				user.phone = $("#phone-register").val();
				user.name = $('#name-register').val();
				//console.log(user);
				
				
					if(user.phone == ""){
					
						alert("请输入手机号");
						
					}else if(user.name == ""){
						
					
						alert("请输入姓名");
					
						
					}else{
					
						$.post('api.php?operation=register',{phone:user.phone,name:user.name}, function(response){
								//console.log(response);
							})
						window.location.href = "controll.php?route=freenewdish";
					}
				
			});




//选择桌号picker in freeNewDish
var pickerDescribe = app.picker.create({
  inputEl: '#desk-free',
    rotateEffect: true,
    cols: [
      {
        textAlign: 'left',
        values: ('包房V 包间B 卡座K 大厅T').split(' ')
      },
      {
        values: ('01 02 03 04 05 06 07 08 09 10 11 12').split(' ')
      },
    ]
});



//点击下单 in freeNewDish.php
$(document).on('click','#getDish', function () {
	user.phone = $('#data-free').text();
	user.dishName = $("#dish").val();
	user.table = $('#desk-free').val();
	console.log(user);
	
	
		if(user.dishName == ""){
		
			alert("请选择菜名");
			
		}else if(user.table == ""){
			
		
			alert("请选择桌号");
		
			
		}else{
		
			$.post('api.php?operation=insertdish',{dish:user.dishName,phone:user.phone,desk:user.table}, function(response){
					if(response == 1){
						//console.log(user);
						//alert("下单成功,菜在25分钟内上桌");
						window.location.assign('controll.php?route=getdishsuccess');
						
						
					}
				})
		
		}
	
});


